*==============================================================================================================
*==============================================================================================================	
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================


* Trustworthy Media and Gender Gaps in Political Participation after Civil War: Experimental Evidence from Rural Liberia

set seed 1234567
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
* MAIN DO - FILE 
* This do-file clean and produce main results of the extension of the  paper.
* For details, read INDEX below

* I DATA CLEANING (line 297)
* II Main Figures and Tables (line 779)
* III. SUPPLEMENTAL MATERIAL TABLES (line 1012) 

* .tex outputs are automatically produced.

* Stata Version 17/18
* RA: Carlos Guastavino. Email: cguastavin@fen.uchile.cl/cgb@dipres.gob.cl 
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================
*==============================================================================================================

	* Clear all stored values in
	* memory from previous projects
	clear all

	*Set default options
	set more 		off
	pause 			on
	set varabbrev 	off

*==============================================================================================================
*		PREPARING GLOBALS & DEFINING PROGRAMMS										
*==============================================================================================================
	
	
	*  User globals
	* -----------
		
	*User Number:
	* Carlos Dropbox 3
	
	global user_number  3

	* Dropbox/Box globals EXAMPLE FOR MAC
	* ---------------------


		if $user_number == 3 {
		global dropbox	"/Users/carlitos/Downloads/Replication_materials-2"
	}


	*Globals*
		global data		"$dropbox/"

	global output		"$dropbox/output/"

set scheme plotplainblind

graph set window fontface "Arial Narrow"

	/*
	*EXAMPLE FOR WINDOWS
			if $user_number == 3 {
		global dropbox	"D:\CGB\Downloads"
	}


	*Globals*
		global data		"$dropbox\\"

	global output		"$dropbox\output\\"
	*/
*use 				"$data\replication_data.dta", replace

	**Open Data**

	
use 				"$data/replication_data.dta", replace

ds
local varlist `r(varlist)'
display "`varlist'"
       

local labtown_name="Town Name"
local labtown_code="Town Code"
local labprogram_type="Programs Done in this community"

label define cov8 5 "UNMIL- Security Exposure only" 7 "UNMIL- Security Exposure+ Civic Education" 
label values program_type cov8 
local labsex="Gender"
local labage="Age"
local labmarit_status="Marit Status"
label define marit_status 1 "Never married" 2 "Married" 3 "Divorced/Separated" 4 "Widowed"
label values marit_status marit_status 
local labschooling="Years of schooling"
local labemployment="Employment Situation"
label define employment 1 "I have no paid work and not looking" 2 "I have no paid work, but I want to find paid work" 3 "I have a little paid work, but I want to find more paid work" 4 "I have enough paid work"
label values employment employment 

local labhhincome="How much was the total cash income? (Liberian Dollars) for HH in the past month"
local labcivsession_num="How many times did you attend the teaching of these human rights people?"
local labsocgroups="In this town, do you have social groups like: dance, theater, PTA, football, or something like that?"
local labecongroups="In this town, do you have farmers' groups to talk about farming issues?"
local labyouthgroups="In this town, do you have youth's group?"
local labwomengroups="In this town, do you have women's group?"
local labpeacecom="In this town, do you have peace or security committee?"
local labdemhrgroups="In this town, do you have democracy or human rights group?"
local labmemfee_pay="In this town, do you pay membership fees for any of these groups?"
local labmet_townchief="Since last january, have you met town chief?"
local labmet_clanchief="Since last january, have you met clan chief?"
local labmet_elders="Since last january, have you met the elders (Poro-Sande)?"
local labmet_police="Since last january, have you met the police?"
local labmet_courts="Since last january, have you met the magistrate-court?"
local labmet_distcom="Since last january, have you met the district commissioner?"
local labmet_cosuper="Since last january, have you met the county superintendent?"
local labmet_mpsen="Since last january, have you met MP-senator?"
local labmet_govoff="Since last january, have you met government official?"
local labcall_radioshow="Since last january, have you called to radio show?"
local labattend_commtng="Since last january, have you attended community meetings?"
local labatcommtng_speak="Did you speak up at the meetings?"
local labattend_voprotest="Since last january, have you attend a riot-violent protest?"
local labattend_polrally="Since last january, have you attend a political rally-speech"
local labvoted_2011="Did you vote?"
local labvoted2011_why="If yes, what was the main reason? (choose one)"
label define voted2011_why 1 "Pick my candidate" 2 "My duty" 3 "Keep peace" 4 "Other"
label values voted2011_why voted2011_why 

local labfictcandidate="Think about the messages these candidates bring you. Now, tell me which Candidate you would like to vote for in an election like the one we just had?"
label define fictcandidate 0 "No one" 1 "Regional candidate" 2 "Ethnic candidate" 3 "National candaidate" 4 "Materialistic candidate"
label values fictcandidate fictcandidate 

         
	  
local labserve_observer="Did you or someone in you HH serve as a party observer in the voting center for the 2011 election?"
local labcampagain_contr="Did you contributed time or money to help someone get elected in this election?"
local labcontactby_party="Before the first round of this past election, were you personally contacted by party representatives asking for your support?"
local labvoting_order="Did anyone tell you who to vote for?"
local labelect_biggift="Did you receive any big gifts like moto-bike or scholarship from authorities for your support in this election?"
local labelect_smallgift="How about small gifts like t-shirt, or hat, or beer from authorities for your support in this election?"
local labelect_fearviolence="During campaigns or election, how much did you fear been a victim of political intimidation or violence?"
label define elect_fearviolence 1 " A lot" 2 "Somewhat" 3 "A little" 4 "Not at all"
label values elect_fearviolence elect_fearviolence 
local labsecretvote_import="How important was it to vote in secret?"
label define secretvote_import 0 "Not important" 1 "Somewhat import" 2 "Very important"

local labvotefor_oldrep="For parliament/house election , did you vote for the old representative who was already in office, or for a new one?"
label define votefor_oldrep 0 "Voted for new one" 1 "Old one" 
label values votefor_oldrep votefor_oldrep 
local labnovoldrep_why="If old one, what was the most important reason?"
label define novoldrep_why 1 "Did not do what he promised" 2 "Other"
label values novoldrep_why novoldrep_why 


local labhhknows_vote="Do you think someone else in your HH knows who voted for?"
local labvcenter_help="At the voting center, anyone helped you to mark you ballot?"
label define vcenter_help 0 "No" 1 "Yes: NEC person" 2 "Yes: Community person" 3 "Yes: Party worker" 4 "Yes: Other"

local labtrouble_votereveal="Do you think you could get in trouble if some big people find out how you voted?"

local labheard_slogan="During campaigns, you heard the slogan, -Baboon wait small; Monkey is still working.- Can you explain what it means?"
label define heard_sloga 0 " Unable" 1 "Able"
label values heard_slogan heard_sloga 


local labhhknows_womenvote="The women in your household, do you know who they voted for?"
local labhhknows_menvote="The men in your household, do you know who they voted for?"
local labthreatif_novote="How often have people threatened bad things to get people to vote the way they like?"
label define threatif_novote 0 " Never/rarely" 1 "Sometimes" 2 "Often"
label values threatif_novote threatif_novote 

local labbigpeople_encviol=" How often have you heard big people in this town telling people to use violence in the elections?"
label values  bigpeople_encviol threatif_novote
local labstopviol_who="If people brought electoral violence here, is there anyone that could stop them?"

label define stopviol_who 0 " No one" 1 "Ys: UNMIL" 2 "Yes: LNP" 3 "Yes: Chief" 4 "Other"
label values stopviol_who stopviol_who 


local labvoteviol_candidate=" Here in Liberia, some people try to use violence like that. Do you think you can give your vote to politicians who encourage violence like that?"
local labsendviol_petition=" Some people are taking a stand against violence. They are sending the two candidates in the runoff election a clear message asking them not to incite violence. I have a petition that you can sign to send the message. Do you want to do it? IF YES: Give the respondent the petition to sign."
local labhavepol_issue="Do you have any issues you would like to raise with local chief district commissioner, your MP, or government in Monrovia?"
label define havepol_issue 1 "You have an issue and you would like to raise it." 2 "You have an issue but you don't want to raise it." 3 "No issues." 
label values havepol_issue havepol_issue 

local labpolsend_card="We have brought with us a card that you can use to send a message to the leader you mentioned about this issue. Do you want to do it?"
local labpolsing_card="IF YES: You can choose to send it with your name or without. Do you want to sign your name?"

local labpref_democgov="Democratic government is preferable to any other kind of government."
label define pref_democgov 0 " No one" 1 "Ys: UNMIL" 2 "Yes: LNP" 3 "Yes: Chief" 4 "Other"
label values pref_democgov pref_democgov

local labwomen_rightrun="Women have the right to be candidate for an elective office."
local labwomen_rightspeak="Women have the right to speak in community meetings."
local labwomen_rightwork="Women have the right to work outside of their home and make their own money."
local labwomen_equalright="In our country, women should have equal rights and same treatment as men."
local labwomen_rightchoose="Women have the right to choose their own candidate and vote in secret."
local labcareful_politics="People should be careful about political talk because they could get in trouble."
local labelectwin_repall="Whoever wins the election represents all Liberians, even people who didn't vote for him/her"
local labgirls_righteduc="Girls have the right to go to school."
local labwomen_rightdivo="Women have the right to divorce their husbands and not give back the dowry."
local labwomen_rightmarry="Women have the right to marry a spouse of their choice."
local labwomen_rightnosex="Women have the right to refuse sex with their husband and not be punished for it."
local labpol_interest="When you get together with friends/family, how often do you discuss political matters?"
local labpol_competent="As far as politics are concerned, how often do friends/family listen to your opinion?"
local labpol_efficacy="How much say do you have in getting leaders to address issues that matter to you?"

foreach x in women_rightrun women_rightspeak women_rightwork women_equalright women_rightchoose careful_politics electwin_repall girls_righteduc women_rightdivo women_rightmarry women_rightnosex pol_interest pol_competent pol_efficacy{
	label values `x' pref_democgov
}

local labsupport_group="It is important for me to support the ideas of other [group] people even if I do not fully agree with them."
local labgrwellbeing_politics="The well-being of [group] people in Liberia has more to do with politics than with our own hard work."
local labgroupfate_affect="What happens to [group] in Liberia will affect"

local labnew3=" What radio station do you listen to the most?"
label define new3 1 "UNMIL Radio" 2 "Other" 
label values new3 new3
local labfavorite_radiooz="Favorite Radio"
local labfavorite_program="What kinds of program do you listen to the most ?"
label define favorite_program 1 "News" 2 "Sports/Music/entertainment" 3 "Human rights/democracy programs"
label values favorite_program favorite_program

local labbuy_newspaper="I brought copies of the major news papers from Monrovia that I can sell to you for 5LD if you are interested. [GIVE BRIEF DESCRIPTIONS.] Are you interested?"

label define buy_newspaper  1 "Not interested" 2 "Interested but cannot read" 3 "Interested but no money"
label values buy_newspaper buy_newspaper


local labmen="Number of men in the town"
local labwomen="Number of women in the town"

forv i=1/4{
	foreach x in men women{
		
		local labbatch`i'_total_`x'=" Attendance Batch `i' (`x')"
	}
}

foreach x in 5 10 20 30 50{
		local labht`x'=" Number of HHs in treated village within `x' kms "
		local labhc`x'=" Number of HHs in control village within `x' kms "
	
}


foreach x in `varlist'{
	label var `x' "`lab`x''"
}

label var pair "Town pair matching"
label var town_on_road "Town is on main road"
label var car_access "Town is accessible by car"
label var women_group "Town has women's group"
label var cell_coverage "Town has cell coverage"
label var community_radio "Town has community radio"
label var voting_center "Town has voting center"
label var pol_party_office "Town has political party office"

* Codebook
preserve
    describe, replace clear
    list
    export excel using "$output//codebook.xlsx", replace first(var)
restore

*==========================================================================
*==========================================================================
*==========================================================================
*I. DATA CLEANING
*==========================================================================
*==========================================================================
*==========================================================================	
	

*============================================================	
*1. RENAME VARIABLES
*============================================================

	rename 	campagain_contr campaign_contr 
	rename 	polsing_card    polsign_card
	
	replace program_type=5 if town_name == "CLEANS TOWN"
	replace program_type=7 if town_name == "KOON TOWN"
	
	
	
	

*============================================================	
*2. MISSING VARIABLES
*============================================================

	ds, has(type numeric)
	foreach var of varlist `r(varlist)' {

		*Question was not asked (N/A) or missing in general
		replace `var' =.a if `var'== -999
		
		*Respondent did not know
		replace `var' =.b if `var'== 88
		
		*Respondent declined to answer
		replace `var' =.c if `var'==99
	 
		*chief survey have -777 where chiefs don't answer in the first place and -999 for N/A with follow up questions - 
		*I am not using these quesitons for now but am not sure what disintion should be made
		replace `var' =.a if `var'== -777
	}

	replace sex=.a if sex==7

	 *string variables still have 88, 99, -999 and -777 observations*

	ds, has(type string)
	foreach var of varlist `r(varlist)' {
		*Question was not asked (N/A) or missing in general
		replace `var' =".a" if `var'=="-999"
		
		*Respondent did not know
		replace `var' =".b" if `var'=="88"
		
		*Respondent declined to answer
		replace `var' =".c" if `var'=="99"
		
		*Question was not asked (N/A) or missing in general
		replace `var' =".a" if `var'=="-777"
		
		}
		
		
		
		

*==================================================================
*3. CREATING DUMMIES
*==================================================================

*------------------------------------------------------------------
*a. DEMOGRAPHIC VARIABLES
*------------------------------------------------------------------
	
	
	foreach var of varlist program_type age marit_status schooling employment {
		gen d`var'=0
		replace d`var' = `var' if `var' == .a | `var' == .b | `var' == .c
	}
	
	replace dprogram_type 	= 1 	if program_type ==5
	replace dage 			= 1 	if age 			> 38
	replace dage 			= .a 	if age 			==2
	replace dmarit_status	= 1 	if marit_status ==2
	replace dschooling		= 1 	if schooling	> 0
	replace demployment		= 1		if employment	==3 	| employment==4


	replace hhincome=.a if hhincome > 50000

*------------------------------------------------------------------
*b. OUTCOME VARIABLES
*------------------------------------------------------------------
	
//	POLITICAL PARTICIPATION
	
*Contacting leaders : create indices
		

	egen metofficial_leaders 	=	rowmean(met_police met_courts met_distcom met_cosuper met_mpsen met_govoff)
	egen metlocal_leaders 		= 	rowmean(met_townchief met_clanchief met_elders)
	

	foreach var of varlist metofficial_leaders metlocal_leaders {
		gen d`var'=0
		replace d`var'=1 if `var'>0 
	}																								//this creates a dummy for haw many people have seen any of them
																										//no need to standardize as all variables are dummies

*Sending card to leaders

		*for stand alone 
	gen 		dpolsend_card 	= 0 	if 	havepol_issue	== 1
	replace 	dpolsend_card 	= 1 	if 	polsend_card  	== 1
	
		*for index
	gen 		dpolsend_index	= 0 	if 	havepol_issue 	== 1 | havepol_issue == 2 | havepol_issue == 3
	replace 	dpolsend_index	= 1 	if 	polsend_card  	== 1
	


*Speak at community meeting

		*for stand alone
	gen 		datcommtng_speak = 0 	if 	attend_commtng  == 1
	replace 	datcommtng_speak = 1 	if 	atcommtng_speak == 1
	
		*for index
	gen 		dcommspeak_index = 0 	if 	attend_commtng  == 0 | attend_commtng == 1
	replace 	dcommspeak_index = 1 	if 	atcommtng_speak == 1
	

	
*------------------------------------------------------------------
*C. DISCUSSION
*------------------------------------------------------------------


//	SECRET BALLOT

*Helped in the polling station
	gen 		dvcenter_help =	   0					if vcenter_help		== 0
	replace		dvcenter_help =	   1					if vcenter_help		== 1  	| vcenter_help == 2  	| 	vcenter_help == 3 | vcenter_help == 4
	replace		dvcenter_help =	   vcenter_help			if vcenter_help		== .a 	| vcenter_help == .b 	| 	vcenter_help == .c 
	
*Importance of secret ballot
	gen 		dsecvote_imp  =	   0					if secretvote_import== 0
	replace		dsecvote_imp =	   1					if secretvote_import== 1  	| secretvote_import == 2  	
	replace		dsecvote_imp =	   secretvote_import	if secretvote_import== .a 	| secretvote_import == .b | secretvote_import == .c 



//  ATTITUDES TO WOMEN

	foreach var of varlist 					women_rightrun women_rightspeak women_rightwork women_equalright 	///
											women_rightchoose girls_righteduc women_rightdivo women_rightmarry 	///
											women_rightnosex {
		gen d`var'=0
		replace d`var'=`var' 	if `var'==.a | `var'==.b | `var'==.c
		replace d`var'=1 		if `var'==1  | `var'==2
	}
	

//	POLITICAL EFFICACY


*Electoral
	gen 	voted2011formycandidate = 0
	replace voted2011formycandidate = 1 if voted2011_why == 1

	gen 	voted2011formyduty = 0
	replace voted2011formyduty = 1 		if voted2011_why == 2

	gen 	voted2011forpeace = 0
	replace voted2011forpeace = 1 		if voted2011_why == 3

	gen 	voted2011forother = 0
	replace voted2011forother = 1 		if voted2011_why == 4

	gen 	strategic_voting = 0
	replace strategic_voting = 1 		if voted2011formycandidate == 1 | voted2011forpeace == 1 |voted2011forother == 1

	gen 	vote_sanction = 0
	replace vote_sanction = 1 			if votefor_oldrep == 0 & novoldrep_why == 1

	recode voting_order 	(1=0) (0=1), generate(voting_order_index)
	recode hhknows_vote 	(1=0) (0=1), generate(hhknows_index)
	recode dvcenter_help	(1=0) (0=1), generate(dvcenter_help_index)

*General
	local 	POT1415		pol_interest pol_competent 
	
	foreach var of local POT1415			{
		gen 		d`var'		=	   	0 			 if `var' ==  1
		replace 	d`var'		=	   	1 			 if `var'  >	 1
		replace 	d`var'		=	   	`var'		 if `var' == .a 		| `var' == .b 		| `var' == .c
	}

	gen 	dpol_efficacy		=	   	0			 if pol_efficacy  == 0
	replace dpol_efficacy		=	   	1			 if pol_efficacy   > 0
	replace dpol_efficacy		=  	   	pol_efficacy if pol_efficacy == .a 	| pol_efficacy == .b| pol_efficacy == .c

	gen 		dbuy_newspaper 	=   	0 			 if buy_newspaper	<= 4 & buy_newspaper >= 1
	replace 	dbuy_newspaper 	=   	1 			 if buy_newspaper	== 4



	
// LIBERAL ORIENTATIONS
	

*Send anti-violence petition

		*for stand alone			 																//because this is a follow on question, we want the proportion
																									//to be of all who gave a yes response to the voting question (BEH4) 
	gen 		dsendviol_petition=0 	if voteviol_candidate==0
	replace 	dsendviol_petition=1 	if sendviol_petition== 1
		*for index
	gen 		dsendviol_index =  0 	if voteviol_candidate==1 | voteviol_candidate== 0
	replace 	dsendviol_index =  1 	if sendviol_petition== 1

	
*Civic voting

		*female sample didn't restrict from missing values previously
	gen 		dfict_candidate =  0 	if fictcandidate	>= 0 & fictcandidate <= 5
	replace 	dfict_candidate =  1 	if fictcandidate	== 3



*Signed message card

		*for standalone analysis																	//sending card (polsend_card) includes missings previously
	gen 		dpolsign_card =    0 	if polsend_card		== 1
	replace 	dpolsign_card =    1 	if polsign_card		== 1
		*for index
	gen 		dpolsign_index=    0 	if polsend_card		== 0 | polsend_card == 1
	replace 	dpolsign_index=    1 	if polsign_card		== 1
	
	
*Freedom of speech, support for democracy and ethnic prejudice

	local 	POT 		 careful_politics pref_democgov electwin_repall // duty_monitorchief
	
	foreach var of local POT					{
		gen 		d`var'	=	   0 			if `var' >=  3
		replace 	d`var'	=	   1 			if `var'  <	 3
		replace 	d`var'	=	   `var'		if `var' == .a 	| `var' == .b | `var' == .c
	}
	
	egen 	democratic_gov 	= 	rowmean(dpref_democgov delectwin_repall)
	egen ethnic_prejudice   =	rowmean(support_group grwellbeing_politics groupfate_affect)


//COLLECTIVE ACTION - MEETING ATTENDANCE
	recode civsession_num (.a = 0), generate(civsessnum_nomissing)   

	gen 		dcivsess_any =	   0					if civsessnum_nomissing	== 0
	replace		dcivsess_any =	   1					if civsessnum_nomissing	>= 1  & civsessnum_nomissing <= 7
	replace		dcivsess_any =	   civsessnum_nomissing	if civsessnum_nomissing == .b | civsessnum_nomissing == .c 

	*median is 2
	gen 		dcivsess_med =	   0					if civsessnum_nomissing	<  2
	replace		dcivsess_med =	   1					if civsessnum_nomissing	>= 2  & civsessnum_nomissing <= 7
	replace		dcivsess_med =	   civsessnum_nomissing	if civsessnum_nomissing == .b | civsessnum_nomissing == .c 


*---------------------------------------------------------------------
*C. LABEL VARIABLES
*---------------------------------------------------------------------

	
		
label var dpol_competent "Political competency (internal)"
label var serve_observer "Served as election observer" 
label var strategic_voting "Strategic voting" 
label var vote_sanction "Vote sanctioning of incumbent" 
label var dbuy_newspaper "Willingness to pay for information"
label var dpol_interest "Interest in politics"
label var dpol_efficacy "Ability to influence political leaders"
label var voting_order_index "Not told who to vote for"
label var hhknows_index "Vote secret from household"
label var dvcenter_help_index "Not helped to vote by anybody"

label var dfict_candidate "Parochial voting"
label var dsendviol_index "Sent anti-violence petition to leader"
label var ethnic_prejudice "Ethnic prejudices"
label var dwomen_equalright "Gender equality under the law"
label var dcareful_politics "Freedom of expression"



********************************************************************************
* Inputting missing values:
********************************************************************************

* Political participation
foreach x in voted_2011 campaign_contr attend_polrally metofficial_leaders			///
						dpolsend_index attend_voprotest call_radioshow attend_commtng		///
						dcommspeak_index metlocal_leaders dmarit_status dage dschooling demployment natnews_unmilradio ///
						{
						
						bys dprogram_type: egen mean_`x'=mean(`x')
						replace `x'=mean_`x' if `x'==.|`x'==.a|`x'==.b
						}

* Other categories:
										foreach x in 	 				serve_observer strategic_voting vote_sanction voting_order_index hhknows_index 	dvcenter_help_index dbuy_newspaper dpol_interest dpol_efficacy dpol_competent dfict_candidate dsendviol_index ethnic_prejudice dwomen_equalright dcareful_politics socgroups econgroups youthgroups womengroups peacecom demhrgroups memfee_pay{
						
						bys dprogram_type: egen mean_`x'=mean(`x')
						replace `x'=mean_`x' if `x'==.|`x'==.a|`x'==.b
						}
						
drop mean*						
ta pair, ge(npair) // matched pairs

ge d=dprogram_type // treatment

*==========================================================================
*==========================================================================
*==========================================================================
*D. MAIN INDICES
*==========================================================================
*==========================================================================
*==========================================================================

*==========================================================================	
*1		-		POLITICAL PARTICIPATION
*==========================================================================

*standardising variables before making index
de voted_2011 campaign_contr attend_polrally metofficial_leaders			///
						dpolsend_index attend_voprotest call_radioshow attend_commtng		///
						dcommspeak_index metlocal_leaders 
						
local indices 	voted_2011 campaign_contr attend_polrally metofficial_leaders			///
						dpolsend_index attend_voprotest call_radioshow attend_commtng		///
						dcommspeak_index metlocal_leaders 
						
		foreach var of local indices {
		cap egen `var'_z = std(`var')
		} 

		egen z 		= 	rowmean(voted_2011_z campaign_contr_z attend_polrally_z metofficial_leaders_z dpolsend_index_z 		/// 
								attend_voprotest_z call_radioshow_z attend_commtng_z dcommspeak_index_z metlocal_leaders_z) // Overall Political participation
							
		egen z_nat 	= 	rowmean(voted_2011_z campaign_contr_z attend_polrally_z metofficial_leaders_z dpolsend_index_z 		///
								attend_voprotest_z call_radioshow_z)  // National political participation
				
		egen z_loc 	= 	rowmean(attend_commtng_z dcommspeak_index_z metlocal_leaders_z) // Local political participation

		foreach var in z z_nat z_loc{
			egen `var'_normal = std(`var')
		}
		
*==========================================================================	
*2		-		POLITICAL EFFICACY
*==========================================================================	


				
	local political efficacy1 efficacy2
	*In /**/ those for the extra exercise. 
	local efficacy serve_observer strategic_voting vote_sanction voting_order_index hhknows_index 	/*dvcenter_help_index*/ dbuy_newspaper /*dpol_interest dpol_efficacy*/ dpol_competent

	foreach var of local efficacy			{
		egen `var'_z 		=	std(`var')
	} 
	
	
	local st_efficacy		 	serve_observer_z strategic_voting_z vote_sanction_z voting_order_index hhknows_index 		///
								 dbuy_newspaper_z  dpol_competent_z
	
	egen efficacy_index 	=	rowmean(`st_efficacy')	
	egen z_eff_index		=	std(efficacy_index) 
	
*==========================================================================	
*3		-		LIBERAL ORIENTATIONS
*==========================================================================	
	

		
	local lib_orientation 			dfict_candidate dsendviol_index ethnic_prejudice dwomen_equalright dcareful_politics 
	
		local political lib_orientation
	
	foreach var of local lib_orientation	{
		egen `var'_z 		=	std(`var')
	} 
	
	local st_lib_orientation 		dfict_candidate_z dsendviol_index_z ethnic_prejudice_z dwomen_equalright_z dcareful_politics_z
	
	egen lib_index				=	rowmean(`st_lib_orientation')	
	egen z_lib_index			=	std(lib_index) 
	
*==========================================================================	
*4 - COORDINATION
*==========================================================================	


local political vote 
local vote socgroups econgroups youthgroups womengroups peacecom demhrgroups 


local soccol  socgroups econgroups youthgroups womengroups peacecom demhrgroups 
 	 
	foreach var of local soccol 	{
		egen `var'_z 		=	std(`var')
	} 
	
	local st_soccol 		socgroups_z econgroups_z youthgroups_z womengroups_z peacecom_z demhrgroups_z
	
	egen soccol_index				=	rowmean(`st_soccol')
	egen z_soccol_index			=	std(soccol_index) 

*==========================================================================
*==========================================================================
*==========================================================================
*==========================================================================
*  II. Main Figures and Tables 
*==========================================================================
*==========================================================================
*==========================================================================
*==========================================================================

*==========================================================================
*==========================================================================
*  A. Figures 
*==========================================================================
*==========================================================================


*==========================================================================
* Figure 2: Effects on political participation indices
*==========================================================================

	local lab0="Male"
	local lab1="Female"
	


preserve
mat def outcomes = J(6,9,.)
	
	local count_out = 0
	local j=1 // number of the family
		local i=1 // number of the outcome
*

local k=1



reg z_normal d npair* if sex==1, vce(cluster town_code)	


foreach var in  z_normal z_nat_normal z_loc_normal {
foreach p in 1 0{

		* Regression analysis: KZG
	local count_out = `count_out' + 1
	qui: reg `var' d npair* if sex==`p', vce(cluster town_code)	 
	eststo mfx		: margins, dydx(d) atmeans post
				mat outcomes[`count_out',1]= r(table)[1,`k']
				mat outcomes[`count_out',2]= r(table)[5,`k']
				mat outcomes[`count_out',3]= r(table)[6,`k']
	qui: reg `var' d npair* if sex==`p', vce(cluster town_code) level(90)	 
	eststo mfx		: margins, dydx(d) atmeans post
				mat outcomes[`count_out',4]= r(table)[5,`k']
				mat outcomes[`count_out',5]= r(table)[6,`k']
				mat outcomes[`count_out',6]= `i'
				mat outcomes[`count_out',7]= `p'+1
				mat outcomes[`count_out',8]= `k'
				
				

}
}



putexcel set "$output/results.xls", sheet("graph") replace

putexcel A1=matrix(outcomes),names
* importing matrix as data
import excel "$output/results.xls", sheet("graph") clear firstrow

forval z=1/2{
mkmat c1-c5 if   c7==`z', matrix(A`z')

matrix A`z'2=A`z''

*A12

}



coefplot  matrix(A22[1,])  matrix(A12[1,]) , ci((2 3) (4 5)) xline(0, lwidth(medium) lcolor(gray) lpattern(solid))  ylabel(, labsize(vsmall))  graphregion(margin(l=25)) coeflabels(r1 = "Overall political participation" r2 = "Institutionalized participation" r3 = "Less institutionalized participation" , labgap(-20)) msize(vsmall) headings(r1 = "{bf:Political Participation indices}" , labsize(vsmall)) ciopts(recast(rcap rspike) lwidth(medium thin)) graphreg(color(gs16)) aspectratio(1.2) legend(order(3 "Female sample" 6 "Male sample"  ) ring(0) bmargin(small) position(1) size(vsmall) rows(8))
graph export "$output/figure2.pdf",replace


restore

*==========================================================================
* Figure 3: Effects on political participation outcomes
*==========================================================================

preserve
mat def outcomes = J(20,9,.)
	
	local count_out = 0
	local j=1 // number of the family
		local i=1 // number of the outcome
*

local k=1


local vote voted_2011 
local campaing campaign_contr attend_polrally 
local contacting dmetofficial_leaders dpolsend_index 
local protest attend_voprotest call_radioshow
local attend attend_commtng dcommspeak_index dmetlocal_leaders

foreach s in  vote campaing contacting protest attend {
	
						local j=`j'+1	

foreach var of local `s' {
forv p=0/1{

		* Regression analysis: KZG
				local count_out = `count_out' + 1
	qui: probit `var' dprogram_type npair* if sex==`p', vce(cluster town_code)	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
				mat outcomes[`count_out',1]= r(table)[1,`k']
				mat outcomes[`count_out',2]= r(table)[5,`k']
				mat outcomes[`count_out',3]= r(table)[6,`k']
	qui: probit `var' dprogram_type npair* if sex==`p', vce(cluster town_code) level(90)	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
				mat outcomes[`count_out',4]= r(table)[5,`k']
				mat outcomes[`count_out',5]= r(table)[6,`k']
				mat outcomes[`count_out',6]= `i'
				mat outcomes[`count_out',7]= `p'+1
				mat outcomes[`count_out',8]= `k'
					local i = `i' + 1
	
		}		

				
		}		

}


putexcel set "$output/results.xls", sheet("graph") replace

putexcel A1=matrix(outcomes),names
* importing matrix as data
import excel "$output/results.xls", sheet("graph") clear firstrow


forval z=1/2{
mkmat c1-c5 if   c7==`z', matrix(A`z')

matrix A`z'2=A`z''

*A12

}


coefplot matrix(A22[1,])  matrix(A12[1,]) , ci((2 3) (4 5)) xline(0, lwidth(medium) lcolor(gray) lpattern(solid))  ylabel(, labsize(vsmall))  graphregion(margin(l=25)) coeflabels(r1 = "Voting in the 2011 election" r2 = "Contributed to campaigns" r3 = "Attended political rallies" r4 = "Contact political leaders" r5 = "Sending card to leaders"r6 = "Attend protests" r7 = "Complaints on radio show" r8 = "Attend community meetings" r9="Speak at community meetings" r10="Contact traditional leaders", labgap(-20)) msize(vsmall) headings(r1 = "{bf:Political Participation Outcomes}" , labsize(vsmall)) ciopts(recast(rcap rspike) lwidth(medium thin)) graphreg(color(gs16)) aspectratio(1.2) legend(order(3 "Female sample" 6 "Male sample"  ) ring(0) bmargin(small) position(1) size(vsmall) rows(8))
graph export "$output/figure3.pdf",replace
restore

*==========================================================================
*==========================================================================
*  B. Tables 
*==========================================================================
*==========================================================================

*==========================================================================
*==========================================================================
* Table 1 Mechanisms associations program
*==========================================================================
*==========================================================================

*==========================================================================
* Mechanisms associations program
*==========================================================================
	capture program drop myratio

program myratio, rclass
  version 17.0
  args x y
  confirm var `x' // mediator
  confirm var `y' // outcome
  * treatment effect on mediator
  reg `x'  d i.pair if sex==1, vce(cluster town_code)
  return scalar col1 = _b[d]
  local c1 = _b[d]
  * association between outcome and mediator in control group
  reg `y' `x' i.pair if d == 0 &  sex==1, vce(cluster town_code)
  return scalar col2 = _b[`x']
  local c2 = _b[`x']
  * treatment effect on outcome
  reg `y' d i.pair if sex==1, vce(cluster town_code)
  local c3denom = _b[d]
  * share explained by mediator
  return scalar col3 = `c1'*`c2'/`c3denom'
end


*==========================================================================
* Estimate:
*==========================================================================	
preserve 
local political efficacy lib_orientation social
  
  label var z_eff_index "Mean index of Political efficacy"
  label var z_lib_index "Mean index of Liberal Orientations" 
  label var z_soccol_index "Mean index of Coordination"
	local efficacy z_eff_index serve_observer strategic_voting vote_sanction voting_order_index hhknows_index 	 dbuy_newspaper  dpol_competent
	local lib_orientation z_lib_index dfict_candidate dsendviol_index ethnic_prejudice dwomen_equalright dcareful_politics 
local social z_soccol_index socgroups econgroups youthgroups womengroups peacecom demhrgroups 

local labefficacy="Political efficacy"
local lablib_orientation="Liberal Orientations"
local labsocial="Coordination"

	keep if sex==1
	forv f=2/2{
foreach s of local political {
foreach var of local `s' {
		local l_`var' : variable label `var'

	bootstrap r(col1) r(col2) r(col3), reps(5000) : myratio  `var' z_normal
		local nd`f'`var'=e(N)
		
		
estat bootstrap, per normal bc
mat a=e(ci_percentile)

	local i=1
	foreach x in _bs_1 _bs_2 _bs_3 {
		local ci_b`var'`i': di %12.3f a[1,`i']
		local ci_u`var'`i': di %12.3f a[2,`i']
		local pvalue = (2 * ttail(360, abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
				local d`var' = _b[`x']
		local `var' = string(round(_b[`x'],.01),"%9.2f")
		local c`var'`x' ``var''`pvalue'
		local s`var'`x' = string(round(_se[`x'],.01),"%9.2f")
	local i=`i'+1	
}

}
}
}


local political2 z_eff_index z_lib_index z_soccol_index

file open Balance_1_Respondent using "${output}/table1.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \footnotesize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{9}{c}}\hline  &  Treatment on mediator & Outcome-mediator & Share explained\\ \hline"											_n		
foreach x in political2  {

foreach s of local `x' {

foreach var of local `s' {
		
		file write Balance_1_Respondent																								_n  ///
"\hline {\textit{`l_`s''}  & `c`s'_bs_1'  & `c`s'_bs_2'   & `c`s'_bs_3'  \\"  _n ///
		"	& [`s`s'_bs_1']   & [`s`s'_bs_2'] & [`s`s'_bs_3']   \\" _n 	///
		"	& (`ci_b`s'1',`ci_u`s'1' )   & (`ci_b`s'2',`ci_u`s'2' )  & (`ci_b`s'3',`ci_u`s'3' )    \\" _n 	///
		
	}

		
}
}
	file write Balance_1_Respondent											_n ///
	"\hline"																			_n ///

	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent


*==========================================================================
*==========================================================================
*==========================================================================
* III. SUPPLEMENTAL MATERIAL TABLES 
*==========================================================================
*==========================================================================
*==========================================================================

*===============================================================================
*TABLES SI 20-22
*===============================================================================

foreach x in political  {

foreach s of local `x' {
file open Balance_1_Respondent using "${output}/mechanisms_new_`s'.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \scriptsize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{12}{c}}\hline  &  Treatment on mediator & Outcome-mediator & Share explained \\ \hline"					
	
		file write Balance_1_Respondent																																	_n ///	
	"\hline \multicolumn{2}{l}{\textbf{`lab`s''}}    \\ \cmidrule{1-1} "  _n
	
foreach var of local `s' {
		
		file write Balance_1_Respondent																								_n  ///
"\hline \textit{`l_`var''}  & `c`var'_bs_1'  & `c`var'_bs_2'   & `c`var'_bs_3'  \\"  _n ///
		"	& [`s`var'_bs_1']   & [`s`var'_bs_2'] & [`s`var'_bs_3']   \\" _n 	///
		"	& (`ci_b`var'1',`ci_u`var'1' )   & (`ci_b`var'2',`ci_u`var'2' )  & (`ci_b`var'3',`ci_u`var'3' )    \\" _n 	///
		
	}

	file write Balance_1_Respondent											_n ///
	"\hline"																			_n ///

	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent		
}
}
restore 

*==========================================================================	
*Table SI 1: Most listened and most listened program (Control group)
*==========================================================================	


ge unmil_most=new3==1|favorite_radiooz=="UNMIL RADIO"|favorite_radiooz=="TRUTH FM/UNMIL"

ge bomi_most=strpos(" " +  favorite_radiooz + " ", " BOMI ")
replace bomi_most=1 if bomi_most>1|favorite_radiooz=="RADIO BOMI/KAKATA"

ge elbc_most=strpos(" " +  favorite_radiooz + " ", " ELBC ")
replace elbc_most=1 if elbc_most>1|favorite_radiooz=="ELBF FM"

ge trusth_most=strpos(" " +  favorite_radiooz + " ", " TRUTH ")
replace trusth_most=1 if trusth_most>1


ge shakta_most=strpos(" " +  favorite_radiooz + " ", " SHAKTA ")
foreach var in SHARTA SHATTA SHATTA SATA SHARKTA SHAKATA {
	qui ge aux=strpos(" " +  favorite_radiooz + " ", " `var' ")
	replace shakta_most=1 if shakta_most>1|aux>0
	drop aux
}

ge other=1-unmil_most-bomi_most-elbc_most-trusth_most-shakta_most if favorite_radiooz!=""
replace other=0 if favorite_radiooz==""
replace other=0 if other<0

ta favorite_program,ge(favorite_program)


local labunmil_most="Most listened radio: UNMIL Radio"
local labbomi_most="Most listened radio: BOMI Radio"
local labelbc_most="Most listened radio: ELBC Radio"
local labtrusth_most="Most listened radio: TRUTH Radio"
local labshakta_most="Most listened radio: SHAKTA Radio"
local labother="Most listened radio: Other Radio"
local labfavorite_program1="Most listened program: News"
local labfavorite_program2="Most listened program: Sport/music/entertainment"
local labfavorite_program3="Most listened program: Human Rights/Democracy"
local labfavorite_program4="Most listened program: Other"



local table3 unmil_most bomi_most elbc_most trusth_most shakta_most other favorite_program1 favorite_program2 favorite_program3 favorite_program4
foreach var of local table3 {
	forv i=0/1{

	qui su `var' if sex==`i' & dprogram_type==0
	local mean_`var'`i': di %12.0f `r(mean)' *100
	local n_`var'`i': di %12.0f `r(N)'
	}

	forv i=0/1{

	qui su `var' if sex==`i' & dprogram_type==1
	local tmean_`var'`i': di %12.0f `r(mean)' *100
	local tn_`var'`i': di %12.0f `r(N)'
	}
}

	file open Balance_1_Respondent using "${output}/table_SI1.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1.3} \small "  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{ll*{9}{c}}\hline & \multicolumn{4}{c}{\textbf{Control }}  \\ \cmidrule(r){2-5} \cmidrule(r){6-9}  & \multicolumn{2}{c}{\textbf{Female sample}} &\multicolumn{2}{c}{\textbf{Male sample}}  \\ \cmidrule(r){2-3} \cmidrule(r){4-5} &  \shortstack{N} & {Mean}  & \shortstack{N}  & {Mean} \\   \hline"											_n		
	foreach var of local table3 {
		
		
	file write Balance_1_Respondent																								_n  ///
"\hline      "  _n ///
"\textit{`lab`var''}  &  `n_`var'1' & `mean_`var'1'\%  & `n_`var'0' & `mean_`var'0'\%     \\"  _n ///


	}

	file write Balance_1_Respondent											_n ///
	"\hline"																			_n ///

	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent

*==========================================================================	
*TABLE SI 2 - Randomization Checks
*==========================================================================	


foreach var of varlist town_on_road car_access women_group cell_coverage community_radio voting_center pol_party_office {
	cap encode `var', gen(n`var')
}


label var ntown_on_road "Town is on main road"
label var ncar_access "Town is accessible by car"
label var nwomen_group "Town has women's group"
label var ncell_coverage "Town has cell coverage"
label var ncommunity_radio "Town has community radio"
label var nvoting_center "Town has voting center"
label var npol_party_office "Town has political party office"

global all_outcomes ntown_on_road ncar_access nwomen_group ncell_coverage ncommunity_radio nvoting_center npol_party_office sex dage dmarit_status dschooling demployment pair
local all_outcomes $all_outcomes

local comm ntown_on_road ncar_access nwomen_group ncell_coverage ncommunity_radio nvoting_center npol_party_office 
local ind sex dage dmarit_status dschooling demployment pair
logit dprogram_type $all_outcomes, vce(cluster town_code)

	margins, 		   dydx(ntown_on_road ncar_access nwomen_group ncell_coverage 			///
							ncommunity_radio nvoting_center npol_party_office sex dage		///
							dmarit_status dschooling demployment)
							
local n=e(N)

	foreach x of local all_outcomes {

		local pvalue = (2 * ttail(500, abs(_b[`x']/_se[`x'])))

        * Allocate stars according to pvalue
			if `pvalue' <= 0.001 {
				local pvalue"***"
						}
			else if `pvalue'>0.001 & `pvalue'<=0.01 {
				local pvalue"**"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"*"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"$^\dagger$"
						}						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_ = string(round(_b[`x'],.01),"%9.2f")
		local c_`x'_ ``x'_'`pvalue'
		local s_`x'_ = string(round(_se[`x'],.01),"%9.2f")
		

		
	 local l_`x' : variable label `x'

}

logit dprogram_type $all_outcomes, vce(cluster town_code)
test $all_outcomes
local pvalue1v : di %12.3f `r(p)'

local labcomm="Community-level characteristics"
local labind="Individual-level factors"

file open Table using "${output}/table_SI2.tex", text write replace

	file write Table  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1.1} \small "  _n

file write Table  _n ///
"\begin{tabular}{l*{1}{c}}\hline & (UNMIL RADIO) \\   \\ \midrule "  _n

foreach s in comm ind{
		file write Table																																	_n ///	
	"\multicolumn{2}{l}{\textbf{`lab`s''}}    \\ \cmidrule{1-1} "  _n
foreach outcome of local `s' {


file write Table " `l_`outcome'' &  `c_`outcome'_'     \\"  _n

file write Table " &  (`s_`outcome'_')    \\"  _n
}
}									

file write Table											_n ///
	"\hline"																			_n ///
	" Wald-chi	(p-value) & `pvalue1v' \\ "		_n ///
	"N	& `n' \\ \hline \hline"	_n 
	

file write Table					_n ///
		"\hline \end{tabular}"													_n

file close Table

*==========================================================================	
*TABLE SI 3 - Attendance
*==========================================================================	
preserve
duplicates drop town_name, force 
foreach x in women  {

	
	forv i=1/4{
		qui su batch`i'_total_`x'
		local batch`i'_total_`x': di %12.0f `r(mean)'
		ge a`x'`i'=batch`i'_total_`x'/`x'*100
		replace a`x'`i'=100 if a`x'`i'>100 & a`x'`i'!=.
		qui su a`x'`i'
		local tbatch`i'_total_`x': di %12.0f `r(mean)'
		
	}
	qui gegen batch_total_`x'=rowmean(batch*_total_`x')
	qui su batch_total_`x'
	local batch_total_`x': di %12.0f `r(mean)'
			ge a`x'=batch_total_`x'/`x'*100
		replace a`x'=100 if a`x'>100 & a`x'!=.	
		 su a`x'
		local tbatch_total_`x': di %12.0f `r(mean)'
}

foreach x in men  {

	
	forv i=1/4{
		qui su batch`i'_total_`x'
		local batch`i'_total_`x': di %12.0f `r(mean)'
		ge a`x'`i'=batch`i'_total_`x'/`batch`i'_total_women'*100
		replace a`x'`i'=100 if a`x'`i'>100 & a`x'`i'!=.
		qui su a`x'`i'
		local tbatch`i'_total_`x': di %12.0f `r(mean)'
		
	}
	qui gegen batch_total_`x'=rowmean(batch*_total_`x')
	qui su batch_total_`x'
	local batch_total_`x': di %12.0f `r(mean)'
			ge a`x'=batch_total_`x'/`batch_total_women'*100
		qui su a`x'
		local tbatch_total_`x': di %12.0f `r(mean)'
}

	file open Balance_1_Respondent using "${output}/table_SI3.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1.3} \small"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{ll*{7}{c}}\hline &\multicolumn{2}{c}{\textbf{Female sample}} &\multicolumn{2}{c}{\textbf{Male sample}}  \\ \cmidrule(r){2-3} \cmidrule(r){4-5}  & \shortstack{N} & \shortstack{Percentage of women \\ living in the village}& \shortstack{N}  & \shortstack{Men attendance as \\ percentage of women attendance}  \\    "											_n		

	forv i=1/4{
		
		
	file write Balance_1_Respondent																								_n  ///
"\hline      "  _n ///
"\textit{Attendance Batch `i'} & `batch`i'_total_women' & `tbatch`i'_total_women'\% & `batch`i'_total_men' & `tbatch`i'_total_men'\%   \\" _n ///



	}
	
	file write Balance_1_Respondent																								_n  ///
"\hline      "  _n ///
"\textit{Attendance Batch (Across 4 weeks)} & `batch_total_women' & `tbatch_total_women'\%  & `batch_total_men' & `tbatch_total_men'\%    \\" _n ///

	file write Balance_1_Respondent											_n ///
	"\hline"																			_n ///

	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent
	restore 


*==========================================================================	
*TABLE SI 4 - Demographics of the Sample (Control group)
*==========================================================================	
*hhincome
local labdmarit_status ="1. Marital status"
local labdage= "2. Age"
local labdschooling= "3. Education"
local labdemployment=  "4. Employment"
local labhhincome=  "5. Employment"

local labdmarit_status1="a. Married"
local labdmarit_status0="b. Unmarried"
local labdage1="a. 18-38"
local labdage0="b. 39-65"
local labdschooling1= "a. Some schooling"
local labdschooling0= "b. No formal school"
local labdemployment1="a. Some paid work reported"
local labdemployment0="b. No paid work reported"
local labhhincome1=  "a. Household (average)"

local table2 dmarit_status dage dschooling demployment 
replace hhincome=.a if hhincome > 50000
foreach var of local table2 {
	forv i=0/1{

	qui su `var' if sex==`i' & dprogram_type==0
	local mean_`var'`i': di %12.0f `r(mean)' *100
	local n_`var'`i': di %12.0f `r(N)'*`r(mean)' 
	local mean_`var'`i'_: di %12.0f (1-`r(mean)')*100
	local n_`var'`i'_: di %12.0f `r(N)'*(1-`r(mean)')
	}
}
foreach var in hhincome {
	forv i=0/1{

	qui su `var' if sex==`i'  & dprogram_type==0
	local mean_`var'`i': di %12.0f `r(mean)' 
	local n_`var'`i': di %12.0f `r(N)' 
	}
}


	file open Balance_1_Respondent using "${output}/table_SI4.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1.3} \small"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{ll*{7}{c}}\hline & &\multicolumn{2}{c}{\textbf{Female sample}} &\multicolumn{2}{c}{\textbf{Male sample}} \\ \cmidrule(r){3-4} \cmidrule(r){5-6} & & \shortstack{N} & {Mean}  & \shortstack{N} & {Mean}  \\ \cmidrule(r){3-4} \cmidrule(r){5-6}   "											_n		
	foreach var of local table2 {
		
		
	file write Balance_1_Respondent																								_n  ///
"\hline      "  _n ///
"\textit{`lab`var''} & \textit{`lab`var'1'} &  `n_`var'1' & `mean_`var'1'\%  & `n_`var'0' & `mean_`var'0'\%   \\"  _n ///
" &  \textit{`lab`var'0'}&  `n_`var'1_' & `mean_`var'1_'\%  & `n_`var'0_' & `mean_`var'0_' \%   \\" _n ///

*		"	&	 &  & `n_`var''   \\" _n 	///

	}
local var="hhincome"
file write Balance_1_Respondent  _n ///
"\hline  \textit{`lab`var''} & \textit{`lab`var'1'} &  `n_`var'1' & `mean_`var'1' (LD)  & `n_`var'0' & `mean_`var'0' (LD)    \\" _n 


	file write Balance_1_Respondent											_n ///
	"\hline"																			_n ///

	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent


*==========================================================================	
*TABLE SI 9 - Summary statistics of the outcome variables
*==========================================================================

cap ge z_pol_index=z_normal 
label var z_pol_index "Mean index of Political Participation index"
label var voted_2011 "Voting in the 2011 election"
label var campaign_contr "Contributed to campaigns"
label var attend_polrally "Attended political rallies"
label var metofficial_leaders "Contact political leaders"
label var attend_voprotest "Attend protests"
label var call_radioshow "Complaints on radio show"
label var attend_commtng "Attend community meetings"
label var dcommspeak_index "Speak at community meetings"
label var metlocal_leaders "Contact traditional leaders"
label var dsendviol_petition "Send anti-violence petition"
label var dpolsend_index "Sending card to leaders"

global pol 	 voted_2011 campaign_contr attend_polrally metofficial_leaders			///
						dpolsend_index attend_voprotest call_radioshow attend_commtng		///
						dcommspeak_index metlocal_leaders 
					
global eff  serve_observer strategic_voting vote_sanction voting_order_index hhknows_index 	/*dvcenter_help_index*/ dbuy_newspaper /*dpol_interest dpol_efficacy*/ dpol_competent


global lib  dfict_candidate dsendviol_index ethnic_prejudice dwomen_equalright dcareful_politics
global soccol  socgroups econgroups youthgroups womengroups peacecom demhrgroups memfee_pay

					
		
local labpol="Political Participation variables"
local labeff="Political Efficacy variables"
local lablib="Liberal Orientations variables"
local labsoccol="Coordination variables"
file open main using "$output/table_SI9.tex", write replace
file write main
file write main "{\setlength{\tabcolsep}{1.5pt}" _n
file write main "\tiny" _n
file write main "\begin{longtable}{lcccccc}" _n

file write main " & (1)  & (2) & (3) & (4) & (5)   \\"  _n
file write main " \headrow  Variable & Mean & SD & Min & Max & N  \\"  _n
file write main "\midrule  " _n


foreach s in pol eff lib soccol {
file write main " \headrow   \multicolumn{6}{l}{{\textit{  `lab`s''}}}  \\"  _n
file write main "\midrule  " _n

foreach x in z_`s'_index $`s' {

qui local lab: variable label `x'
qui su `x',d
		local mean_`x'`i'= string(r(mean),"%9.2f")
		local sd_`x'`i'= string(r(sd),"%9.2f")
		local min_`x'`i'= string(r(min),"%9.0f")
		local max_`x'`i'= string(r(max),"%9.0f")
		local n_`x'`i'= string(r(N),"%9.0f")
file write main " {`lab'}  & `mean_`x'`i'' & `sd_`x'`i'' & `min_`x'`i'' & `max_`x'`i'' & `n_`x'`i''  \\"  _n
}
file write main "\midrule  " _n
}
file write main "\bottomrule" _n
file write main "\end{longtable}" _n
file close main

	
*==========================================================================	
* table SI 10 A
*==========================================================================	
local labvoted_2011="Voting in the 2011 election"
local labcampaign_contr="Contributed to campaigns"
local labattend_polrally="Attended political rallies"
local labdmetofficial_leaders="Contact political leaders"
local labmetofficial_leaders="Contact political leaders"
local labdpolsend_card="Sending card to leaders"
local labattend_voprotest="Attend protests"
local labcall_radioshow="Complaints on radio show"
local labattend_commtng="Attend community meetings"
local labdatcommtng_speak="Speak at community meetings"
local labdmetlocal_leaders="Contact traditional leaders"
local labmetlocal_leaders="Contact traditional leaders"
local labdsendviol_petition="Send anti-violence petition"
local labvoting_test="Voting test"
local labdfict_candidate="Civic voting"
local labdbuy_newspaper="Buy news news paper"
local labdpolsign_card="Signed message card"
local labdpol_efficacy="Political efficacy"
local labdpol_interest="Political interest"
local labdwomen_rightrun="Support for women's rights to run"
local labdwomen_rightspeak="Support for women's right to speak"
local labdwomen_rightwork="Support for women's rights to work"
local labdwomen_equalright="Support for women's equal rights"
local labdwomen_rightchoose="Support for women's rights to choose"
local labdgirls_righteduc="Support for girls' rights to go to school"
local labdwomen_rightmarry="Support for women's rights to marry"
local labdwomen_rightnosex="Support for women's rights to refuse sex"
local labdwomen_rightdivo="Support for women's rights to divorce"

local labdpolsend_index="Sending card to leaders"
local labdcommspeak_index="Speak at community meetings"
local labdpolsign_index="Signed message card"
local labdsendviol_index="Send anti-violence petition"

local labpolitical="Indicators of political participation"
local labcampaing="Campaigning"
local labvote="Electoral participation"
local labcontacting="Contacting"
local labprotest="Protesting"
local labattend="Communing"
cap label var polparticipation2_index "Political participation index"
label var z_normal "Political participation index"
cap label var polparticipation2m_index "Political participation index"

local political vote campaing contacting protest attend
local vote voted_2011 
local campaing campaign_contr attend_polrally 
local contacting metofficial_leaders dpolsend_index 
local protest attend_voprotest call_radioshow
local attend attend_commtng dcommspeak_index metlocal_leaders


local table5 voted_2011 campaign_contr attend_polrally metofficial_leaders 		///
						dpolsend_index 	attend_voprotest call_radioshow attend_commtng 		///
						dcommspeak_index metlocal_leaders 	 

	
		
foreach var of local table5 {
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* if sex==1, vce(cluster town_code)
	 local n`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local prog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local sd_prog_`var': di %12.3f b[1,1]
	local change_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}

local i=1
forv f=1/1{
foreach var in z_normal{
		local l_`var' : variable label `var'
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* if sex==`f', vce(cluster town_code)
	local n`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local c_`x'_`var'`f' ``x'_`var''`pvalue'
		local s_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}


*===============================================================================
*===============================================================================

foreach var of local table5 {
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* if sex==0, vce(cluster town_code)
	 local mn`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local mprog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local msd_prog_`var': di %12.3f b[1,1]
	local mchange_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}
*polparticipation2m_index
local i=1
forv f=1/1{
foreach var in z_normal{
		local l_`var' : variable label `var'
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* if sex==0, vce(cluster town_code)
	local mn`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local mc_`x'_`var'`f' ``x'_`var''`pvalue'
		local ms_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}

	file open Balance_1_Respondent using "${output}/table_SI10A.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \footnotesize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{9}{c}}\hline \headrow &\multicolumn{3}{c}{\textbf{Panel A: Female Sample}} &\multicolumn{3}{c}{\textbf{Panel B: Male Sample}} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \headrow &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change} &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change}  \\ \hline"											_n		
			file write Balance_1_Respondent																								_n  ///
"\hline \textit{`l_z_normal'} & `mean_z_normal'  & `c_d_z_normal1' & & `mmean_z_normal'  & `mc_d_z_normal1'  \\"  _n ///
		"	& & [`s_d_z_normal1'] & & & [`ms_d_z_normal1']     \\" _n 	///
		"	& &   & & &     \\" _n 	
foreach x in political  {

	
foreach s of local `x' {

foreach var of local `s' {
		
		
	file write Balance_1_Respondent																								_n  ///
"\textit{`lab`var''}  & `mean_`var'' & `prog_`var'1'  &  `change_`var''\% & `mmean_`var'' & `mprog_`var'1'  &  `mchange_`var''\%  \\"  _n ///
		"	&	 & [`sd_prog_`var''] & &  & [`msd_prog_`var'']  &   \\" _n 	///
		"	&	 &  & &   &  &    \\" _n 	///

	}
}
}


	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent


*==========================================================================	
* table SI 10 B
*==========================================================================	


local table5 voted_2011 campaign_contr attend_polrally metofficial_leaders 		///
						dpolsend_index 	attend_voprotest call_radioshow attend_commtng 		///
						dcommspeak_index metlocal_leaders 	 

global all_outcomes  nwomen_group  ncommunity_radio nvoting_center npol_party_office sex dage dmarit_status dschooling demployment 	


foreach var of local table5 {
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* $all_outcomes if sex==1, vce(cluster town_code)
	 local n`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local prog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local sd_prog_`var': di %12.3f b[1,1]
	local change_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}

local i=1
forv f=1/1{
foreach var in z_normal{
		local l_`var' : variable label `var'
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* $all_outcomes if sex==`f', vce(cluster town_code)
	local n`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local c_`x'_`var'`f' ``x'_`var''`pvalue'
		local s_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}


*===============================================================================
*===============================================================================

foreach var of local table5 {
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* $all_outcomes if sex==0, vce(cluster town_code)
	 local mn`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local mprog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local msd_prog_`var': di %12.3f b[1,1]
	local mchange_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}

local i=1
forv f=1/1{
foreach var in z_normal{
		local l_`var' : variable label `var'
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* $all_outcomes if sex==0, vce(cluster town_code)
	local mn`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local mc_`x'_`var'`f' ``x'_`var''`pvalue'
		local ms_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}

	file open Balance_1_Respondent using "${output}/table_SI10B.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \footnotesize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{9}{c}}\hline \headrow &\multicolumn{3}{c}{\textbf{Panel A: Female Sample}} &\multicolumn{3}{c}{\textbf{Panel B: Male Sample}} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \headrow &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change} &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change}  \\ \hline"											_n		
			file write Balance_1_Respondent																								_n  ///
"\hline \textit{`l_z_normal'} & `mean_z_normal'  & `c_d_z_normal1' & & `mmean_z_normal'  & `mc_d_z_normal1'  \\"  _n ///
		"	& & [`s_d_z_normal1'] & & & [`ms_d_z_normal1']     \\" _n 	///
		"	& &   & & &     \\" _n 	
foreach x in political  {

	
foreach s of local `x' {

foreach var of local `s' {
		
		
	file write Balance_1_Respondent																								_n  ///
"\textit{`lab`var''}  & `mean_`var'' & `prog_`var'1'  &  `change_`var''\% & `mmean_`var'' & `mprog_`var'1'  &  `mchange_`var''\%  \\"  _n ///
		"	&	 & [`sd_prog_`var''] & &  & [`msd_prog_`var'']  &   \\" _n 	///
		"	&	 &  & &   &  &    \\" _n 	///

	}
}
}


	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent

*===============================================================================
*===============================================================================
* TABLES SI 11- SI 16: Heterogeneity analysis:
*===============================================================================
*===============================================================================
local labvoted_2011="Voting in the 2011 election"
local labcampaign_contr="Contributed to campaigns"
local labattend_polrally="Attended political rallies"
local labdmetofficial_leaders="Contact political leaders"
local labdpolsend_card="Sending card to leaders"
local labattend_voprotest="Attend protests"
local labcall_radioshow="Complaints on radio show"
local labattend_commtng="Attend community meetings"
local labdatcommtng_speak="Speak at community meetings"
local labdmetlocal_leaders="Contact traditional leaders"
local labdsendviol_petition="Send anti-violence petition"
local labvoting_test="Voting test"
local labdfict_candidate="Civic voting"
local labdbuy_newspaper="Buy news news paper"
local labdpolsign_card="Signed message card"
local labdpol_efficacy="Political efficacy"
local labdpol_interest="Political interest"
local labdwomen_rightrun="Support for women's rights to run"
local labdwomen_rightspeak="Support for women's right to speak"
local labdwomen_rightwork="Support for women's rights to work"
local labdwomen_equalright="Support for women's equal rights"
local labdwomen_rightchoose="Support for women's rights to choose"
local labdgirls_righteduc="Support for girls' rights to go to school"
local labdwomen_rightmarry="Support for women's rights to marry"
local labdwomen_rightnosex="Support for women's rights to refuse sex"
local labdwomen_rightdivo="Support for women's rights to divorce"

local labdpolsend_index="Sending card to leaders"
local labdcommspeak_index="Speak at community meetings"
local labdpolsign_index="Signed message card"
local labdsendviol_index="Send anti-violence petition"

local labpolitical="Indicators of political participation"
local labcampaing="Campaigning"
local labvote="Electoral participation"
local labcontacting="Contacting"
local labprotest="Protesting"
local labattend="Communing"
cap label var polparticipation2_index "Political participation index"
cap label var polparticipation2m_index "Political participation index"

local political vote campaing contacting protest attend
local vote voted_2011 
local campaing campaign_contr attend_polrally 
local contacting dmetofficial_leaders dpolsend_index 
local protest attend_voprotest call_radioshow
local attend attend_commtng dcommspeak_index dmetlocal_leaders

local labdmarit_status ="1. Marital status"
local labdage= "2. Age"
local labdschooling= "3. Education"
local labdemployment=  "4. Employment"
local labhhincome=  "5. Employment"

cap ge chdi=natnews_unmilradio==0 if natnews_unmilradio!=.

local labdmarit_status1="a. Married"
local labdmarit_status0="b. Unmarried"
local labdage1="a. 18-38"
local labdage0="b. 39-65"
local labdschooling1= "a. Some schooling"
local labdschooling0= "b. No formal school"
local labdemployment1="a. Some paid work reported"
local labdemployment0="b. No paid work reported"
local labhhincome1=  "a. Household (average)"



local table2 dmarit_status dage dschooling demployment 
cap replace hhincome=.a if hhincome > 50000


local table5 voted_2011 campaign_contr attend_polrally dmetofficial_leaders 		///
						dpolsend_index 	attend_voprotest call_radioshow attend_commtng 		///
						dcommspeak_index dmetlocal_leaders 	 

cap rename dmarit_status dmar
cap rename dschooling dsch
cap rename demployment demp
cap rename hhincome hhin

qui su hhin,d
cap ge dhhin=hhin>r(p50)

cap ge pol_index=z_normal
*
local t=1
foreach z in dmar dage dsch demp  dhhin chdi{
	forv l=0/1{
	 
		preserve 

keep if `z'==`l'  
foreach var of local table5 {
	sum `var' if sex==1 & d==0
	
	local mean_`var'`l' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* if sex==1, vce(cluster town_code)
	 local n`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local prog_`var'1`l'="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local sd_prog_`var'`l': di %12.3f b[1,1]
	local change_`var'`l': di %12.0f  (`prog_`var''/`mean_`var'`l'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'`l'')*100
}

local i=1
forv f=1/1{
foreach var in z_normal{
		local l_`var' : variable label `var'
	sum `var' if sex==1 & d==0
	
	local mean_`var'`l' : di %12.2f `r(mean)'
	
	reg `var' d npair* if sex==`f', vce(cluster town_code)
	local n`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local c_`x'_`var'`f'`l' ``x'_`var''`pvalue'
		local s_`x'_`var'`f'`l' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}
restore
}

*===============================================================================
*===============================================================================


	file open Balance_1_Respondent using "${output}/het_`t'_2024.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \footnotesize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{9}{c}}\hline \headrow &\multicolumn{3}{c}{\textbf{Panel A: `lab`z'0'}} &\multicolumn{3}{c}{\textbf{Panel B: `lab`z'1'}} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \headrow &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change} &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change}  \\ \hline"											_n		
			file write Balance_1_Respondent																								_n  ///
"\hline \textit{`l_z_normal'} & `mean_z_normal0'  & `c_d_z_normal10' & & `mean_z_normal1'  & `c_d_z_normal11'  \\"  _n ///
		"	& & [`s_d_z_normal10'] & & & [`s_d_z_normal11']     \\" _n 	///
		"	& &   & & &     \\" _n 	
foreach x in political  {

	
foreach s of local `x' {
	*	file write Balance_1_Respondent																																	_n ///	
	*"\hline \multicolumn{2}{l}{\textbf{`lab`s''}}    \\ \cmidrule{1-1} "  _n
foreach var of local `s' {
		
		
	file write Balance_1_Respondent																								_n  ///
"\textit{`lab`var''}  & `mean_`var'0' & `prog_`var'10'  &  `change_`var'0'\%  & `mean_`var'1' & `prog_`var'11'  &  `change_`var'1'\%  \\"  _n ///
		"	&	 & [`sd_prog_`var'0'] & &  & [`sd_prog_`var'1']  &   \\" _n 	///
		"	&	 &  & &   &  &    \\" _n 	///

	}
}
}

	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent

	local t=`t'+1
}
*===============================================================================
* TABLE 17: Alternative index construction
*===============================================================================

local outcomes "voted_2011 campaign_contr attend_polrally metofficial_leaders dpolsend_index attend_voprotest call_radioshow attend_commtng dcommspeak_index metlocal_leaders"
	 
	 local group_ "" 
	 local counter = 0 
	
	
	foreach var of local outcomes {	
	 	
		    							 // Define local to store number of variable
			local l_`var' : variable label `var'
			
			local counter = `counter' + 1
		
	 * Create standardize version of each var

			    sum `var' if dprogram_type == 0 & sex==1			  				// Summarize variable over control 
				
				if `r(N)' > 0 {
				local group_ "`group_' st_`var'_w"
				
				cap gen st_`var'_w = (`var' - r(mean))/r(sd)					
				label var st_`var'_w "Standardised within `l_`var''"
        
				}
	 
	}
	
	 **Average all the z-scores 	
		
		egen    polparticipation2_index = rowtotal(`group_') ,m				// this will sum all the st_* variables
		replace polparticipation2_index = polparticipation2_index/`counter'             // Divide it by the total number of variables which is 6 in our case
 

local labvoted_2011="Voting in the 2011 election"
local labcampaign_contr="Contributed to campaigns"
local labattend_polrally="Attended political rallies"
local labdmetofficial_leaders="Contact political leaders"
local labmetofficial_leaders="Contact political leaders"
local labdpolsend_card="Sending card to leaders"
local labattend_voprotest="Attend protests"
local labcall_radioshow="Complaints on radio show"
local labattend_commtng="Attend community meetings"
local labdatcommtng_speak="Speak at community meetings"
local labdmetlocal_leaders="Contact traditional leaders"
local labmetlocal_leaders="Contact traditional leaders"
local labdsendviol_petition="Send anti-violence petition"
local labvoting_test="Voting test"
local labdfict_candidate="Civic voting"
local labdbuy_newspaper="Buy news news paper"
local labdpolsign_card="Signed message card"
local labdpol_efficacy="Political efficacy"
local labdpol_interest="Political interest"
local labdwomen_rightrun="Support for women's rights to run"
local labdwomen_rightspeak="Support for women's right to speak"
local labdwomen_rightwork="Support for women's rights to work"
local labdwomen_equalright="Support for women's equal rights"
local labdwomen_rightchoose="Support for women's rights to choose"
local labdgirls_righteduc="Support for girls' rights to go to school"
local labdwomen_rightmarry="Support for women's rights to marry"
local labdwomen_rightnosex="Support for women's rights to refuse sex"
local labdwomen_rightdivo="Support for women's rights to divorce"
 *% CHANGE
local labdpolsend_index="Sending card to leaders"
local labdcommspeak_index="Speak at community meetings"
local labdpolsign_index="Signed message card"
local labdsendviol_index="Send anti-violence petition"

local labpolitical="Indicators of political participation"
local labcampaing="Campaigning"
local labvote="Electoral participation"
local labcontacting="Contacting"
local labprotest="Protesting"
local labattend="Communing"
cap label var polparticipation2_index "Political participation ASTE index"
label var z_normal "Political participation MEAN index"
cap label var polparticipation2m_index "Political participation index"

local political vote campaing contacting protest attend
local vote voted_2011 
local campaing campaign_contr attend_polrally 
local contacting metofficial_leaders dpolsend_index 
local protest attend_voprotest call_radioshow
local attend attend_commtng dcommspeak_index metlocal_leaders


*eststo mfx		: margins, dydx(dprogram_type) atmeans post
local table5 voted_2011 campaign_contr attend_polrally metofficial_leaders 		///
						dpolsend_index 	attend_voprotest call_radioshow attend_commtng 		///
						dcommspeak_index metlocal_leaders 	 
*voted_2011 campaign_contr attend_polrally dmetofficial_leaders dpolsend_index attend_voprotest call_radioshow attend_commtng dcommspeak_index dmetlocal_leaders

	
		
foreach var of local table5 {
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* if sex==1, vce(cluster town_code)
	 local n`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local prog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local sd_prog_`var': di %12.3f b[1,1]
	local change_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}

local i=1
forv f=1/1{
foreach var in z_normal polparticipation2_index{
		local l_`var' : variable label `var'
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* if sex==`f', vce(cluster town_code)
	local n`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local c_`x'_`var'`f' ``x'_`var''`pvalue'
		local s_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}


foreach var of local table5 {
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* if sex==0, vce(cluster town_code)
	 local mn`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local mprog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local msd_prog_`var': di %12.3f b[1,1]
	local mchange_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}
*polparticipation2m_index
local i=1
forv f=1/1{
foreach var in z_normal polparticipation2_index{
		local l_`var' : variable label `var'
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* if sex==0, vce(cluster town_code)
	local mn`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local mc_`x'_`var'`f' ``x'_`var''`pvalue'
		local ms_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}

	file open Balance_1_Respondent using "${output}/table_SI17.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \footnotesize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{9}{c}}\hline \headrow &\multicolumn{3}{c}{\textbf{Panel A: Female Sample}} &\multicolumn{3}{c}{\textbf{Panel B: Male Sample}} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \headrow &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change} &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change}  \\ \hline"											_n		
			file write Balance_1_Respondent																								_n  ///
"\hline \textit{`l_z_normal'} & `mean_z_normal'  & `c_d_z_normal1' & & `mmean_z_normal'  & `mc_d_z_normal1'  \\"  _n ///
		"	& & [`s_d_z_normal1'] & & & [`ms_d_z_normal1']     \\" _n 	///
		"	& &   & & &     \\" _n 	
		
			file write Balance_1_Respondent																								_n  ///
" \textit{`l_polparticipation2_index'} & `mean_polparticipation2_index'  & `c_d_polparticipation2_index1' & & `mmean_polparticipation2_index'  & `mc_d_polparticipation2_index1'  \\"  _n ///
		"	& & [`s_d_polparticipation2_index1'] & & & [`ms_d_polparticipation2_index1']     \\" _n 	///
		"	& &   & & &     \\ \hline" _n 	
foreach x in political  {

	
foreach s of local `x' {
	*	file write Balance_1_Respondent																																	_n ///	
	*"\hline \multicolumn{2}{l}{\textbf{`lab`s''}}    \\ \cmidrule{1-1} "  _n
foreach var of local `s' {
		
		
	file write Balance_1_Respondent																								_n  ///
"\textit{`lab`var''}  & `mean_`var'' & `prog_`var'1'  &  `change_`var''\% & `mmean_`var'' & `mprog_`var'1'  &  `mchange_`var''\%  \\"  _n ///
		"	&	 & [`sd_prog_`var''] & &  & [`msd_prog_`var'']  &   \\" _n 	///
		"	&	 &  & &   &  &    \\" _n 	///

	}
}
}


	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent

*===============================================================================
* TABLE 18: Spatial Analysis
*===============================================================================

preserve 





local z=50
local f=1
	reg z_normal d npair* hc`z' ht`z' if sex==`f', vce(cluster town_code)

local i=1
forv f=0/1{
foreach var in z_normal {
foreach z in 5 10 20 30 50{
		local l_`var' : variable label `var'
	sum `var' if sex==`f' & d==0
	
	local mean`f'_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* hc`z' ht`z' if sex==`f', vce(cluster town_code)
	local m`f'`z'=e(N)

	
	foreach x in d hc`z' ht`z'{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local m`z'c_`x'_`var'`f' ``x'_`var''`pvalue'
		local m`z's_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}

}
}
}

	file open Balance_1_Respondent using "${output}/table_SI18.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \footnotesize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{11}{c}}\hline \headrow &\multicolumn{4}{c}{\textbf{Panel A: Female Sample}} &\multicolumn{4}{c}{\textbf{Panel B: Male Sample}} \\ \cmidrule(r){2-5}\cmidrule(l){6-9} \headrow &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & \shortstack{\gamma_{1}} & \shortstack{\gamma_{2}}   &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & \shortstack{\gamma_{1}} & \shortstack{\gamma_{2}}  \\ \hline"											_n		

foreach z in 5 10 20 30 50{

	file write Balance_1_Respondent																								_n  ///
"\hline \textit{`z' kms radius}  & `mean1_z_normal'  & `m`z'c_d_z_normal1' & `m`z'c_ht`z'_z_normal1' & `m`z'c_hc`z'_z_normal1'     & `mean0_z_normal'  & `m`z'c_d_z_normal0' & `m`z'c_ht`z'_z_normal0' & `m`z'c_hc`z'_z_normal0' \\"  _n ///
		"	 & & [`m`z's_d_z_normal1'] & [`m`z's_ht`z'_z_normal1'] & [`m`z's_hc`z'_z_normal1']  & & [`m`z's_d_z_normal0'] & [`m`z's_ht`z'_z_normal0'] & [`m`z's_hc`z'_z_normal0']   \\" _n 	///
		"	& &   & & &     \\" _n 	

}

	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent
	
	restore
	
*===============================================================================
*===============================================================================
*  Table S19: Alternative mechanism (leaders' influence)
*===============================================================================
*===============================================================================


ge delect_fearviolence=elect_fearviolence!=4 if elect_fearviolence!=.a & elect_fearviolence!=.b
ge dthreatif_novote=threatif_novote!=0 if threatif_novote!=.a & threatif_novote!=.b
ge dbigpeople_encviol=bigpeople_encviol!=0 if bigpeople_encviol!=.a & bigpeople_encviol!=.b
ge unmilstopviol_who=stopviol_who==1 if stopviol_who!=.a & stopviol_who!=.b
ge lnpstopviol_who=stopviol_who==2 if stopviol_who!=.a & stopviol_who!=.b
ge chiefstopviol_who=stopviol_who==3 if stopviol_who!=.a & stopviol_who!=.b

ge notdsecvote_imp=1-dsecvote_imp
ge notheard_slogan=1-heard_slogan
local labcontactby_party="Party representatives asked support"
local labelect_biggift="Big gifts from authorities"
local labelect_smallgift="Small gifts from authorities" 
local labdelect_fearviolence="Fear of being victim of political violence" 
*local labelectvio_partyldr="" 
local labnotdsecvote_imp="Not important to vote in secret" 
local labdvcenter_help="Not helped to vote by anybody"
local labtrouble_votereveal="Get in trouble if vote reveal" 
local labnotheard_slogan="Not able to explain the slogan" 
local labhhknows_womenvote="Vote revealed to the women of the HH" 
local labhhknows_menvote="Vote revealed to the men of the HH" 
local labdthreatif_novote="Threatened to vote" 
local labdbigpeople_encviol="Big people encourage electoral violence" 
local labunmilstopviol_who="UNMIL could stop electoral violence"
local lablnpstopviol_who="LNP could stop electoral violence"
local labchiefstopviol_who="Chief could stop electoral violence"


local table3 contactby_party elect_biggift elect_smallgift delect_fearviolence  notdsecvote_imp dvcenter_help trouble_votereveal notheard_slogan hhknows_womenvote hhknows_menvote dthreatif_novote dbigpeople_encviol 
						
		foreach var of local table3 {
		cap egen `var'_z = std(`var')
		} 
		
drop z_normal

		egen z_normal 		= 	rowmean(contactby_party_z elect_biggift_z elect_smallgift_z delect_fearviolence_z  notdsecvote_imp_z dvcenter_help_z trouble_votereveal_z notheard_slogan_z hhknows_womenvote_z hhknows_menvote_z dthreatif_novote_z dbigpeople_encviol_z ) 

		
foreach var of local table3 {
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* if sex==1, vce(cluster town_code)
	 local n`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local prog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local sd_prog_`var': di %12.3f b[1,1]
	local change_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}

local i=1
forv f=1/1{
foreach var in z_normal{
		local l_`var' : variable label `var'
	sum `var' if sex==1 & d==0
	
	local mean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* if sex==`f', vce(cluster town_code)
	local n`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local c_`x'_`var'`f' ``x'_`var''`pvalue'
		local s_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}


*===============================================================================
*===============================================================================

foreach var of local table3 {
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	 probit `var' dprogram_type npair* if sex==0, vce(cluster town_code)
	 local mn`var'=e(N)
	 
	 
	eststo mfx		: margins, dydx(dprogram_type) atmeans post
	
	ereturn list 
	mat MARGIN = _b[dprogram_type]

	local pvalue = (2 * ttail(500, abs(_b[dprogram_type]/_se[dprogram_type])))
		* Variable pvalue is used afterwards to produce FDR pvalues.

        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		
	local a=MARGIN[1,1]
	local prog_`var': di %12.3f `a'
	local mprog_`var'1="`prog_`var''`pvalue'"
	mat b=_se[dprogram_type] 
	local msd_prog_`var': di %12.3f b[1,1]
	local mchange_`var': di %12.0f  (`prog_`var''/`mean_`var'')*100
	di as result "percent change for prog_`var'="(`prog_`var''/`mean_`var'')*100
}
*polparticipation2m_index
local i=1
forv f=1/1{
foreach var in z_normal{
		local l_`var' : variable label `var'
	sum `var' if sex==0 & d==0
	
	local mmean_`var' : di %12.2f `r(mean)'
	
	reg `var' d npair* if sex==0, vce(cluster town_code)
	local mn`f'`i'=e(N)

	
	foreach x in d{

		local pvalue = (2 * ttail(e(df_r), abs(_b[`x']/_se[`x'])))
		
        * Allocate stars according to pvalue
			if `pvalue' <= 0.01 {
				local pvalue"***"
						}
			else if `pvalue'>0.01 & `pvalue'<=0.05 {
				local pvalue"**"
						}
			else if `pvalue'>0.05 & `pvalue'<=0.1 {
				local pvalue"*"
						}
						
			else {
				local pvalue""
			}
		* Coefficient with corresponding star level as local value as well as sd.
		local `x'_`var' = string(round(_b[`x'],.01),"%9.2f")
		local mc_`x'_`var'`f' ``x'_`var''`pvalue'
		local ms_`x'_`var'`f' = string(round(_se[`x'],.01),"%9.2f")
		
}
local i=`i'+1

}
}

local l_z_normal="Index of Negative Leader's Influence"

	file open Balance_1_Respondent using "${output}/table_SI19.tex", text write replace
	
		file write Balance_1_Respondent  _n ///
"\setlength{\tabcolsep}{6pt} \renewcommand{\arraystretch}{1} \footnotesize"  _n

	file write Balance_1_Respondent										_n ///
	"\begin{tabular}{l*{9}{c}}\hline \headrow &\multicolumn{3}{c}{\textbf{Panel A: Female Sample}} &\multicolumn{3}{c}{\textbf{Panel B: Male Sample}} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \headrow &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change} &  \shortstack{Control \\ Mean}  &  \shortstack{Marginal \\Impact} & {\% Change}  \\ \hline"											_n		


			file write Balance_1_Respondent																								_n  ///
"\hline \textit{`l_z_normal'} & `mean_z_normal'  & `c_d_z_normal1' & & `mmean_z_normal'  & `mc_d_z_normal1'  \\"  _n ///
		"	& & [`s_d_z_normal1'] & & & [`ms_d_z_normal1']     \\" _n 	///
		"	& &   & & &     \\" _n 		
	*	file write Balance_1_Respondent																																	_n ///	
	*"\hline \multicolumn{2}{l}{\textbf{`lab`s''}}    \\ \cmidrule{1-1} "  _n
foreach var of local table3 {
		
		
	file write Balance_1_Respondent																								_n  ///
"\textit{`lab`var''}  & `mean_`var'' & `prog_`var'1'  &  `change_`var''\% & `mmean_`var'' & `mprog_`var'1'  &  `mchange_`var''\%  \\"  _n ///
		"	&	 & [`sd_prog_`var''] & &  & [`msd_prog_`var'']  &   \\" _n 	///
		"	&	 &  & &   &  &    \\" _n 	///

	}

	
	file write Balance_1_Respondent									_n ///
	"\hline \end{tabular}"														_n
		
	file close Balance_1_Respondent

*===============================================================================
*===============================================================================
*===============================================================================
* Analysis using Afrobarometer
*===============================================================================
*===============================================================================
*===============================================================================
* You need to download the relevant data here: https://www.afrobarometer.org/data/data-sets/?select-countries%5B%5D=liberia&hidden-current-page=1


********************************************************************************
* Importing the data
********************************************************************************

import spss RESPNO BACKCHK URBRUR REGION DISTRICT DISTRICT_NUM CLAN EA_SVC_A EA_SVC_B EA_SVC_C EA_SVC_D EA_FAC_A EA_FAC_B EA_FAC_C EA_FAC_D EA_FAC_E EA_SEC_A EA_SEC_B EA_ROAD NOCALL_1 NOCALL_2 NOCALL_3 NOCALL_4 NOCALL_5 NOCALL_6 NOCALL_7 PREVINT THISINT ADULT_CT CALLS DATEINTR STRTIME Q1 Q2 Q3 Q3OTHER Q4A Q4B Q5 Q6A Q6B Q7A Q7B Q8A Q8B Q8C Q8D Q8E Q9A Q9B Q9C Q10 Q11 Q12A Q12B Q12C Q13 Q14 Q15A Q15B Q15C Q16 Q17 Q18 Q19 Q20 Q21 Q22A Q22B Q23A Q23B Q23C Q23C1_LIB Q23D Q24A Q24B Q25A Q25B Q25C Q26A Q26B Q27A Q27B Q27C Q28A Q28B Q29A Q29B Q29C Q30 Q31 Q32 Q33 Q34 Q35 Q36 Q37 Q38 Q39 Q40A Q40B Q41A1 Q41A2 Q41B1 Q41B2 Q42A Q42B Q42C Q42D Q43 Q44A Q44B Q44C Q44D_LIB Q44E_LIB Q45A Q45B Q45C Q45D Q45E Q45F_LIB Q46 Q47 Q48A Q48B Q49A Q49B Q49C Q49D Q49E Q49F Q49G Q49H Q49I Q49J_LIB Q49K_LIB Q49L_LIB Q49M_LIB Q50A Q50B Q50C Q50D Q50E Q50F Q50G Q50H Q51A Q51B Q51C Q52 Q53A Q53B Q54A Q54B Q54C Q55 Q56PT1 Q56PT2 Q56PT3 Q57A Q57B Q57C Q57D Q57E Q57F Q57G Q57H Q57I Q57J Q57K Q57L Q57M Q57N Q57O Q57P Q58A Q58B Q58C Q58D Q58E Q58F Q58G Q58H Q59A Q59B Q59C Q59D Q59E Q59F Q60A Q60B Q60C Q60D Q60E Q60F Q61 Q62A1 Q62A Q62B Q62C Q62D Q62E Q62F Q63A Q63B Q63C Q63D Q63E_LIB Q64A Q64B Q64C Q64D Q64E Q65 Q66 Q67 Q68 Q69 Q70A Q70B Q70C Q71 Q72A Q72B Q73A Q73B Q73C Q74 Q75APT1_LIB Q75APT2_LIB Q75APT3_LIB Q75B_LIB Q75C_LIB Q76_LIB Q77A_LIB Q77B_LIB Q78A_LIB Q78B_LIB Q78C_LIB Q78D_LIB Q78E_LIB Q78F_LIB Q78G_LIB Q78H_LIB Q78I_LIB Q78J_LIB Q78K_LIB Q78L_LIB Q79 Q79OTHER Q80 Q81 Q82 Q83 Q84A Q84B Q84C Q85 Q86 Q87 Q88A Q88B Q88C Q88D Q88E Q88F Q89 Q90 Q91 Q92A Q92B Q92C Q93A Q93B Q94 Q95 Q96 Q97 Q98A Q98B Q98C Q98D Q98E Q98F Q98G Q98H Q98I Q98J1 Q98K Q99A Q99B Q99C Q100 ENDTIME LENGTH Q101 Q102 Q103 Q104 Q105A Q105B Q105C Q105D Q105E Q106 Q107A Q107B Q107C Q108A Q108B Q108C Q108D Q108E Q108F Q110 Q111 Q112 Q113 Q114 Q115 Withinwt in 1/1200 using "$data/lib_r4_data.sav", clear

********************************************************************************
* Relevant graph 
********************************************************************************

ge female=Q101==2
ge male=Q101==1
global variables Q12A Q12B Q12C Q13 Q14 Q15A Q15B Q15C Q16 Q17 Q18 Q19 Q20 Q21 Q22A Q22B Q23A Q23B Q23C Q23C1_LIB Q23D Q24A Q24B Q25A Q25B Q25C Q26A Q26B Q27A Q27B Q27C Q28A Q28B Q29A Q29B Q29C Q30 Q31 Q32 Q33 Q34 Q35 Q36 Q37 Q38 Q39 Q40A Q40B Q41A1 Q41A2 Q41B1 Q41B2 Q42A Q42B Q42C Q42D Q43 Q44A Q44B Q44C Q44D_LIB Q44E_LIB Q45A Q45B Q45C Q45D Q45E Q45F_LIB Q46 Q47 Q48A Q48B Q49A Q49B Q49C Q49D Q49E Q49F Q49G Q49H Q49I Q49J_LIB Q49K_LIB Q49L_LIB Q49M_LIB Q50A Q50B Q50C Q50D Q50E Q50F Q50G Q50H Q51A Q51B Q51C Q52 Q53A Q53B Q54A Q54B Q54C Q55 Q56PT1 Q56PT2 Q56PT3 Q57A Q57B Q57C Q57D Q57E Q57F Q57G Q57H Q57I Q57J Q57K Q57L Q57M Q57N Q57O Q57P Q58A Q58B Q58C Q58D Q58E Q58F Q58G Q58H Q59A Q59B Q59C Q59D Q59E Q59F Q60A Q60B Q60C Q60D Q60E Q60F Q61 Q62A1 Q62A Q62B Q62C Q62D Q62E Q62F Q63A Q63B Q63C Q63D Q63E_LIB Q64A Q64B Q64C Q64D Q64E Q65 Q66 Q67 Q68 Q69 Q70A Q70B Q70C Q71 Q72A Q72B Q73A Q73B Q73C Q74

global variables2 Q12A Q12B Q12C Q13 Q14 Q15A Q15B Q15C Q16 Q17 Q18 Q19 Q20 Q21 Q22A Q22B Q23A Q23B Q23C Q23C1_LIB Q23D Q30 Q62A Q62B Q62C Q62D Q62E Q62F Q87 Q88A Q88B Q88C Q92A Q92B

global variables2 Q88A Q88B Q88C Q92A Q13 Q14 Q15B Q15C Q23A Q23B Q23D Q16 Q20 Q21 Q12A Q12C


replace Q23D=. if Q23D==-1|Q23D==9
replace Q23D=0 if Q23D==3
replace Q23D=2 if (Q23D>3 & Q23D!=.)

label define labels25 0 "You were not registered", modify

label define labels18 1 "Totally agree With Statement 1", modify
label define labels18 4 "Totally agree With Statement 2", modify



********************************************************************************
foreach outcome in $variables2{
preserve
local l_`outcome': variable label `outcome'

replace `outcome'=. if `outcome'==9
collapse (sum) male female , by(`outcome')

replace male=100*male/599
replace female=100*female/601
*ytitle("`l_`outcome''")
label var male "Male"
label var female "Female"
graph bar male female, over(`outcome', label(angle(45))) blabel(bar, format(%5.1f))  legend(order(1 "Male" 2 "Female"))
graph export "$output/pdf_`outcome'.pdf",replace
restore
}

file open Table using "$data/coefplot.tex", text write replace

foreach outcome in $variables2{
	local l_`outcome': variable label `outcome'

	file write Table																																	_n ///	
	"\begin{figure}[!htb] "  _n
	
		file write Table																																	_n ///	
	"\centering "  _n

			file write Table																																	_n ///	
	"\caption{ `l_`outcome''' (Average by gender in percentage) }\includegraphics{graphs/pdf_`outcome'.pdf} \label{`outcome'}  "  _n
	
	
file write Table																																	_n ///
      "\end{figure}"  _n	  
	  

}

file close Table 
